package org.openCage.artig;

import org.openCage.artig.stjx.Artifact;
import org.openCage.artig.stjx.Artig;
import org.openCage.artig.stjx.ArtigFromXML;
import org.openCage.artig.stjx.Project;
import org.openCage.io.fspath.FSPath;

public class ArtigUtils {

    private String getLibraryLocation(Artifact arti) {
        return arti.getGroupId().replace('.', '/')  + "/" + arti.getName() + "/" + arti.getVersion() + "/" + arti.getName() + "-" + arti.getVersion() + ".jar" ;
    }

    public static FSPath getLibraryLocation( FSPath base, Artifact arti) {

        return base.addPackage( arti.getGroupId() ).add( arti.getName(), arti.getVersion(), arti.getName() + "-" + arti.getVersion() + ".jar" );
    }


    public static Artig readArtig( FSPath base ) {

        if ( !base.toFile().exists() ) {
            return null;
        }
        
        for ( String name : base.toFile().list() ) {
            if ( name.endsWith( ".artig" )) {
                return ArtigFromXML.read( base.add( name ).toFile());
            }
        }

        return null;
    }


}
